express = require 'express'
config = require './config/config'
cors = require './middlewares/cors'
oauth = require './middlewares/oauth'
stylus = require './middlewares/stylus'
engines = require 'consolidate'

module.exports = app = express()

#
# App Setting
#

app.configure ->
  app.set 'view engine', 'jade'
  app.set 'views', __dirname + '/views'
  app.engine 'hbs', engines.handlebars

  app.use express.bodyParser()
  app.use express.methodOverride()
  app.use express.favicon()
  app.use express.cookieParser()
  app.use express.cookieSession
    secret: config.session.secret
  app.use cors
  app.use oauth.oauth()
  app.use oauth.login()
  app.use app.router
  app.use stylus
  app.use express.static __dirname + '/public'

app.configure 'development', ->
  app.use express.errorHandler
    dumpExceptions: true
    showStack: true

app.configure 'production', ->
  app.use express.errorHandler()
